<?php

/**
 * Description of Dimension1
 * 
 * @author yahn 
 */
class Dimension1 {

    private $refD1, $nom;
    private $lesDimensions2 /*= array()*/;

    public function __construct(array $donnees) {
        $this->hydrate($donnees);
        $this->lesDimensions2 = array();
    }

    public function hydrate(array $donnees) {
        foreach ($donnees as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (method_exists($this, $method)) {
                $this->$method($value);
            }
        }
    }

    /**
     * Attribue un nom à cette Dimension1
     * @param type $nom nom de la Dimension 1
     */
    public function setNom($nom) {
        if (is_string($nom)) {
            $this->nom = $nom;
        }
    }

    public function setRefD1($refD1) {
        $this->refD1 = $refD1;
    }

    public function getRefD1() {
        return $this->refD1;
    }

    public function getNom() {
        return $this->nom;
    }

    public function getLesDimensions2($position = null) {
        if (isset($position)) {
            return $this->lesDimensions2[$position];
        } else {
            return $this->lesDimensions2;
        }
    }

    public function addDimension2($d2) {

        if (is_array($d2)) {
            
            $this->lesDimensions2 = $d2;
        } elseif(get_class($d2)=='Dimension2') {
            
            $this->lesDimensions2[] = $d2;
        }
    }
    
    public function setDimension2($d2) {
        $this->lesDimensions2=$d2;
    }

    /* public function __toString() {
      $text =  "<b>Dimension1 :</b> <br> Ref :".$this->refD1."<br> Nom:".$this->nom;

      return $text;
      } */
}

?>
